package com.yuhs.zixing.pay.util;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

/**
 * @className: DataCenterId
 * @description: DataCenterId
 * @author: xiaofei
 * @create: 2020年01月20日
 */
final class DataCenterId {

    public final static long getDataCenterId(long maxDatacenterId) {
        int pid = getPid();
        return (pid % maxDatacenterId);
    }

    /**
     * 获取当前进程的PID值.
     * @return
     */
    public final static int getPid() {
        final RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
        String pid = mxBean.getName().split("@")[0];
        int $pid = Integer.parseInt(pid, 10);
        return $pid;
    }

    private DataCenterId() {
        throw new AssertionError("Uninstantiable class.");
    }
}
